<?

include_once("./_common.php");

auth_check($auth[$sub_menu], "r");
$token = get_token();

if ($is_admin != "super")
    alert("최고관리자만 접근 가능합니다.");

$g4['title'] = "배너관리";

$colspan=5;

include_once ("./admin.head.php");

$query="Select * From info_banner Where 1 Order By no desc;";
$result=mysql_query($query);
$total_count = mysql_num_rows($result);

$rows = $config[cf_page_rows];
$total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
if (!$page) $page = 1; // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함

$sql="Select * From info_banner Where 1 Order By No Desc Limit $from_record, $rows;";
$result = sql_query($sql);
?>
<table width=100% cellpadding=3 cellspacing=1>
	<tr>
	    <td width=50% align=left> (배너수 : <?=number_format($total_count)?>개)</td>
	</tr>
</table>
<form name=flist method=post action='<?=$PHP_SELF?>'>
	<input type=hidden name=page value="<?=$page?>">
	<input type=hidden name=mode value="">
	<table cellpadding=0 cellspacing=0 class="board_list" style="text-align: center">
		<col width=30>
		<col width=500>
		<col width=200>
		<col width=130>
		<col width=40/>
		<tr>
		    <th >&nbsp;</th>
			<th>이미지</th>
			<th>설명</th>
			<th>사용</th>
			<th><a href="./site_banner_form.php?bo_table=banner"><img src='./img_btn/plus_btn.gif' border=0 title='배너생성'></a></td>
		</tr>
		<?
			for ($i = 0; $row = mysql_fetch_array($result); $i++) {
				$bg = $i%2 ? 0 : 1;
				$check_use=$row[check_use];
				if (!$check_use) $check_use = 'N'; ?>
				<tr class="bg<?=$bg?>">
					<td>
						<input type=checkbox name="num[]" value="<?=$row['no']?>">
					</td>
					<input type=hidden name='no[]' value='<?=$row['no']?>'>
					<td >&nbsp;<img src="<?=$g4['path']."/banner_img/".$row['img_file']?>" width="500px" /></td>
					<td ><?=$row['memo']?></td>
					<td >
						<select id="use_select" name='use_yn' class=ed onchange="javascript:use_toggle();">
							<option value="Y" <?if($check_use=='Y') echo "selected";?> >사용중</option>
							<option value="N" <?if($check_use=='N') echo "selected";?> >일시중지</option>
						</select>
					</td>
					<td >
						<a href="./site_banner_form.php?bo_table=banner&mode=modify&no=<?=$row[no]?>"><img src='./img_btn/co_btn_modify.gif' border=0 title='수정'></a>
					</td>
				</tr>
				 <?
			}
			if (!$total_count) { ?>
				
				<tr><td colspan='<?=$colspan?>' align=center height=100 bgcolor=#ffffff>설정된 배너가 없습니다.</td></tr>
				<?
			}
		?>
	</table>
	<table width=100% cellpadding=3 cellspacing=1>
		<tr>
			<td>
				<input type=button value='선택'  onclick="multiCheck(1);" class=btn1>
				<input type=button value='취소'  onclick="multiCheck(2);" class=btn1>
				<input type=button value='반전'  onclick="multiCheck(3);" class=btn1>
				&nbsp;&nbsp;
				<input  type=button value="선택 삭제" onclick="javascript:selected_delete();" class=btn1>
				<input  type=button value="전체 삭제" onclick="delete_all()" class=btn1>
			</td>
			<td align=right>
				<?
					$pagelist = get_paging($config[cf_write_pages], $page, $total_page, "?page=");
					echo $pagelist;
				?>
			</td>
		</tr>
	</table>
</form>
<script language=javascript>
function multiCheck(n)
{
	var i;
	var l = document.getElementsByName('num[]');

	for (i = 0; i < l.length; i++) {
		if (n == 1) l[i].checked = true;
		if (n == 2) l[i].checked = false;
		if (n == 3) l[i].checked = !l[i].checked;
	}
}

function delete_all()
{
	if (confirm('삭제후 복구가 불가능합니다 정말로 실행하시겠습니까?')) {
		$.ajax({
			url:'./site_banner_update.php',
			data: {
	  			mode: 'delete_all'
			}
		}).done(function(msg) {
			if (msg == 'OK') {
				location.reload(true);
			}
		});
	}

	return false;
}

var selected_delete = function() {
	var selected_items = new Array();
	var i;
	var j = 0;
	var l = document.getElementsByName('num[]');

	for (i = 0; i < l.length; i++) {
		if (l[i].checked == true) {
			j++;

			selected_items.push(l[i].value);
		}
	}

	if (j == 0)	{
		alert('선택된 데이타가 없습니다.');
		return false;
	}

	$.ajax({
		url:'./site_banner_update.php',
		data: {
  			mode: 'delete_selected',
  			use_value: selected_items
		}
	}).done(function(msg) {
		//alert(msg);
		if (msg == 'OK') {
			location.reload(true);
		}
		//document.write(msg);
	});
}

var use_toggle = function() {
	$.ajax({
		url:'./site_banner_update.php',
		data: {
  			mode: 'use_toggle',
  			use_value: $('#use_select option:selected').val()
		}
	}).done(function(msg) {
		//alert(msg);
	});
}
</script>
<?
include_once("../admin.tail.php");
?>
